package oj0329.oj0329_01;


import java.util.Scanner;

class SeqStack{
    private static final int stackSize = 10;
    private int top;
    private int[] data;

//    初始化栈
    public SeqStack(){
        top = -1;   //栈顶
        data = new int[stackSize];
    }

//    入栈
    public void push(int x){
        //遍历栈，找到下个空位，再赋值
//        top是索引，所以遍历到 最大长度-1 的地方栈满了 不能再加
        if (top == stackSize - 1){
            System.out.println("Stack is Full");
            return;
        }
        top++;
        data[top] = x;
    }

//    出站 栈顶元素
    public int pop(){
//        空栈
        if (isEmpty()){
            System.out.println("Stack is Empty");
            return -1;
        }
        int p = data[top];
        top--;
        return p;
    }

    //获取栈顶元素
    public int getTop(){
        if (isEmpty()){
            System.out.println("Stack is Empty");
            return -1;
        }
        return data[top];
    }

    //栈判空
    public boolean isEmpty(){
        return top == -1;
    }
}



public class Main {
    public static void main(String[] args) {
        SeqStack stack = new SeqStack();
        Scanner scanner = new Scanner(System.in);
        int row = scanner.nextInt();  //操作行数
        int res;
        for (int i = 0; i < row; i++) {
            int a = scanner.nextInt();
            if (a > 3 || a < 1){
                break;
            }
            switch (a){
                case 1:
                    int b = scanner.nextInt();
                    stack.push(b);
                    break;
                case 2:
                    stack.pop();
                    break;
                case 3:
                    res = stack.getTop();
                    if (res != -1){
                        System.out.println(res);
                    }
                    break;
                default:
                    break;
            }

        }
        scanner.close();
    }

}

